<extend name="./app/Tpl/Public/template.html" />
<block name="content_body">
	<div class="pad-lr-10">
	    <div style="padding:10px; overflow:hidden;">
	    	<div class="main_top" style="clear:both;"><h4>温馨提示：</h4>
    			<ul>
    				<li class="green">1.取消订单：是指配送人员未进行配送；全部退货：是指配送人员配送完，客户提出的不要了</li>
    			</ul>
	    	</div>
	    </div>
	   	<div class="order_workflow">
	   		<ul >
	   			<li>
	   				<dl class="{$steps['step1']['step_active']}">
	   					<dt>新订单<span class="arrow {$steps['step1']['arrow_active']}"></span></dt>
	   					<dd>{$shop.name}</dd>
	   					<dd>{$order.cust_order_time|date="Y-m-d H:i:s",###}</dd>
	   				</dl>
	   			</li>
	   			<li>
	   				<dl class="{$steps['step2']['step_active']}">
	   					<dt>商品打包<span class="arrow {$steps['step2']['arrow_active']}"></span></dt>
	   					<if condition="$order['order_status'] eq 1">
	   						<dd>
	   							<select name="shop_saler" id="shop_saler" style="width:85px">
			                		<volist name="users" id='val'>
			                			<option value="{$val.id},{$val.name},{$val.mobile}">{$val.name}</option>
			                		</volist>
			                		<option value="0,其他,其他">其他</option>
			                	</select>
	   						</dd>
	   						<dd>
	   							<input type="button"  name="form_list_btn_cancelOne" value="开始打包" onclick="readyPackage()"/>
	   						</dd>
	   					<else/>
	   						<dd>
	   							{$order.shop_saler_name}
	   						</dd>
	   						<dd>
	   							<if condition="$order['shop_saler_name'] eq ''">
	   								未指定打包人员
	   							<else/>
	   								{$order.shop_saler_time|date="Y-m-d H:i:s",###}
	   							</if>
	   						</dd>
	   					</if>
	   				</dl>
	   			</li>
	   			<li>
	   				<dl class="{$steps['step3']['step_active']}">
	   					<dt>订单配送<span class="arrow {$steps['step3']['arrow_active']}"></span></dt>
	   					<if condition="$order['order_status'] eq 2">
	   						<dd>
	   							<select name="shop_sender" id="shop_sender"  style="width:85px">
			                		<volist name="users" id='val'>
			                			<option value="{$val.id},{$val.name},{$val.mobile}">{$val.name}</option>
			                		</volist>
			                		<option value="0,其他,其他">其他</option>
			                	</select>
	   						</dd>
	   						<dd>
	   							<input type="button"  name="form_list_btn_cancelOne" value="开始配送" onclick="readySend()"/>
	   						</dd>
	   					<else/>
	   						<dd>
	   							{$order.shop_sender_name}&nbsp;
	   						</dd>
	   						<dd>
	   							<if condition="$order['shop_sender_name'] eq ''">
	   								未指定配送人员
	   							<else/>
	   								{$order.shop_sender_time|date="Y-m-d H:i:s",###}
	   							</if>
	   						</dd>
	   					</if>
	   				</dl>
	   			</li>
	   			<li>
	   				<dl class="{$steps['step4']['step_active']}">
	   					<dt>客户支付<span class="arrow {$steps['step4']['arrow_active']}"></span></dt>
	   					<if condition="$order['order_status'] eq 3">
	   						<dd>
	   							<input type="button"  name="form_list_btn_cancelOne" value="部分退货" onclick="readyPay('1','部分退货')" />
								<input type="button"  name="form_list_btn_cancelOne" value="全部退货" onclick="readyPay('2','全部退货')" />
	   						</dd>
	   						<dd>
	   							<input type="button"  name="form_list_btn_cancelOne" value="全额支付" onclick="readyPay('0','全额支付')"/>
	   						</dd>
	   					<else/>
	   						<dd>
	   							<if condition="$order['order_status'] eq 4 OR $order['order_status'] eq 0">
									<switch name="order.cust_order_status" >
										<case value="0">订单正常</case>
										<case value="1">部分退货</case>
										<case value="2">全部退货</case>
										<case value="3">订单取消</case>
										<default />
									</switch>
								<else/>
									<input type="button"  name="form_list_btn_cancelOne" value="部分退货"  disabled/>
									<input type="button"  name="form_list_btn_cancelOne" value="全部退货"  disabled/>
								</if>
	   						</dd>
	   						<dd>
	   							<if condition="$order['order_status'] eq 4 OR $order['order_status'] eq 0">
									<switch name="order.cust_order_status" >
										<case value="0">已支付</case>
										<case value="1">已支付</case>
										<case value="2">未支付</case>
										<case value="3">未支付</case>
										<default />
									</switch>
								<else/>
									<input type="button"  name="form_list_btn_cancelOne" value="全额支付"  disabled/>
								</if>
	   						</dd>
	   					</if>
	   				</dl>
	   			</li>
	   			<li>
	   				<dl class="{$steps['step0']['step_active']}">
	   					<dt>结单</dt>
	   					<if condition="$order['order_status'] eq 4">
	   						<dd>
	   							&nbsp;
	   						</dd>
	   						<dd>
	   							<input type="button"  name="form_list_btn_cancelOne" value="结单" onclick="finishOrder()"/>
	   						</dd>
	   					<elseif condition="$order['order_status'] eq 0"/>
	   						<dd>
	   							&nbsp;
	   						</dd>
	   						<dd>
	   							已结单
	   						</dd>
	   					<else/>
	   						<dd>
								<input type="button"  name="form_list_btn_cancelOne" value="取消订单"  onclick="readyPay('3','取消订单')"/>
	   						</dd>
	   						<dd>
	   							<input type="button"  name="form_list_btn_cancelOne" value="结单"  disabled/>
	   						</dd>
	   					</if>
	   				</dl>
	   			</li>	   				   				   			
	   		</ul>
		</div>

	    <form name="form_list_edit" id="form_list_edit" action="{:U('doAdd')}" method="post" class="table_form_box">
			<div class="table-list">
			    <table width="100%" cellspacing="0">
			    	<caption style="background:#9c6;color:#fff;text-align:left;margin:0 0; padding:5px 10px; font-size:12px;font-weight:700;">商品清单<span class="blue">【{$shop.title}，{$shop.name}】</span></caption>
			        <thead>
			            <tr> 
			            	<th width="80">序号</th>               
			                <th width="200" align="left">商品名称</th>
			                <th width="80" align="left">规格</th>
			                <th width="80" align="left">购买价格</th>
			                <th width="80" align="left">购买数量</th>
							<th width="80" align="left">退货数量</th>
							<th width="80" align="left">总额</th>
			      			<th align="left">操作</th>
			            </tr>
			        </thead>
			    	<tbody>
			    		<if condition="$order['prod_cancel_edit'] eq 1">
							<volist name="items" id='val'>
					        <tr>
					        	<td align="center">{$i}<input type="hidden" name="id" value="{$val.id}"></td>
								<td align="left">{$val.prod_name}</td>
								<td align="left">{$val.prod_spec|m_prod_spec=$val['prod_spec_qty'],$val['prod_spec_unit']}</td>
								<td align="left">¥{$val.prod_price_real}</td>
								<td align="left">{$val.prod_num}</td>
								<td align="left">
									<input type="number" name="prod_cancel_num[]" id="prod_cancel_num{$val.id}" min="0" max="{$val.prod_num}"  size="4" value="{$val.prod_cancel_num}">
								</td>
								<td align="left">¥{$val['prod_price_real']*($val['prod_num'] - $val['prod_cancel_num'])}</td>
					            <td align="left" class="btn">
					            	<input type="button"  name="form_list_btn_cancelOne" value="退货" onclick="cancelItem('{$order.order_code}','{$val.id}')"/>
									<span id="prod_cancel_text{$val.id}">
									<if condition="$val['prod_cancel_num'] gt 0">
					            		已退货
					            	</if>
					            	</span>
					            </td>
					        </tr>
					        </volist>
				        <else/>
				        	<volist name="items" id='val'>
					        <tr>
					        	<td align="center">{$i}<input type="hidden" name="id" value="{$val.id}"></td>
								<td align="left">{$val.prod_name}</td>
								<td align="left">{$val.prod_spec|m_prod_spec=$val['prod_spec_qty'],$val['prod_spec_unit']}</td>
								<td align="left">¥{$val.prod_price_real}</td>
								<td align="left">{$val.prod_num}</td>
								<td align="left">{$val.prod_cancel_num}</td>
								<td align="left">¥{$val['prod_price_real']*($val['prod_num'] - $val['prod_cancel_num'])}</td>
					            <td align="left" class="btn">
					            	<if condition="$val['prod_cancel_num'] gt 0">
					            		退货商品<if condition="$val['prod_cancel_stock_flag'] eq 0">(未入库)</if>
					            	</if>
					            </td>
					        </tr>
					        </volist>
				        </if>
			    	</tbody>
			    </table>
			 </div>
	    </form>
	    <br>
	    <form name="form_edit" id="form_edit" action="{:U('showDetail')}" method="post" class="table_form_box">
	    	<input type="hidden" name="order_code" value="{$order.order_code}">
	    	<input type="hidden" name="upd_time" value="{$order.upd_time}">
	    	<input type="hidden" name="cust_order_status" value="">
	    	<input type="hidden" name="shop_saler" value="">
	    	<input type="hidden" name="shop_sender" value="">
	        <table width="100%" cellpadding="2" cellspacing="1" class="table_form">
	        	<caption>订单信息<span class="red">【<?php echo m_k2v(C('CST_ORDER_STATUS'),$order['order_status']); ?>】</span></caption>
	            <tr>
	                <th width="10%">订单号码:</th>
	                <td width="40%">{$order.order_code}</td>
	                <th>下单时间:</th>
	                <td>{$order.cust_order_time|date="Y-m-d H:i:s",###}</td>
	                
	            </tr>
	            <tr>
	                <th>订单金额:</th>
	                <td>¥{$order.order_amt}</td>
	                <th width="10%" rowspan="3">订单备注:</th>
	                <td width="40%" rowspan="3">
	                	<textarea name="order_bak" rows=5 cols="50">{$order.order_bak}</textarea>
	                	<input type="button"  name="form_list_btn_cancelOne" value="编辑备注" onclick="updOrderBak()"/>
	                </td>
	            </tr>
	            <tr>
					<th width="10%">配送费用:</th>
	                <td width="40%">
	                	
	                	<if condition="$order['order_status'] neq 0">
	                		<input type="number" name="order_send_fee" size="4" value="{$order.order_send_fee}"><input type="button"  name="form_list_btn_cancelOne" value="修改配送费" onclick="updOrderSendFee()"/>
	                	<else/>
	                		¥{$order.order_send_fee}
	                	</if>
	                </td>
	            </tr>
	            <tr>
					<th width="10%">实付金额:</th>
	                <td width="40%">
	                	<if condition="$order['cust_pay_amt'] eq 0">
	                		<span class="red">未支付</span>
	                	<else/>
	                		¥{$order.cust_pay_amt}
	                	</if>
	                </td>
	            </tr>	                                 
			</table>
			<table width="100%" cellpadding="2" cellspacing="1" class="table_form">
				<caption>客户信息</caption>
	            <tr>
	                <th width="10%">客户名称:</th>
	                <td width="40%">{$order.cust_name}</td>
	                <th width="10%">配送要求:</th>
	                <td width="40%">{$order.cust_free_time}</td>
	            </tr>
	            <tr>
	                <th >联系方式:</th>
	                <td >{$order.cust_mobile}</td>
	               	<th rowspan="2">客户备注:</th>
	                <td rowspan="2">{$order.cust_bak}</td>
	            </tr>
	            <tr>
	            	<th >配送地址:</th>
	                <td >{$order.cust_address}</td>

	            </tr>
	    	</table>
	   	</form>
	   	<br>
	</div>
	<div class="PrintArea orderPrint">
		
		<table class="tablePrint" cellspacing="5" style="font-size:12px">
			<caption>
				<div class="headerPrint" style="vertical-align:bottom;font-size:12px;"><image src="__ROOT__/statics/images/logo.png" width="100"/>http://www.59likesong.com</div>
				<div style="display:inline">
					<div class="fl">订单号:{$order.order_code}</div>
					<div class="fr">收货人：{$order.cust_name},{$order.cust_mobile}</div>
				</div><br>
				<div style="display:inline">
					<div class="fl">下单日期:{$order.cust_order_time|date="Y-m-d",###}</div>
					<div class="fr">配送地址：{$order.cust_address}</div>
				</div>
				
			</caption>
			<thead>
				<tr>
					<th align="left" width="50%">商品名称</th>
					<th align="left" width="20%">规格</th>
					<th align="left" width="10%">数量</th>
					<th align="left" width="10%">单价</th>
					<th align="left" width="10%">合计</th>
				</tr>
			</thead>
			<tbody>
				<volist name="items" id='val'>
		        <tr>
					<td align="left">{$val.prod_name}</td>
					<td align="left">{$val.prod_spec|m_prod_spec=$val['prod_spec_qty'],$val['prod_spec_unit']}</td>
					<td align="left">{$val['prod_num']-$val['prod_cancel_num']}</td>
					<td align="left">￥{$val.prod_price_real}</td>
					<td align="left">￥{$val['prod_price_real']*($val['prod_num'] - $val['prod_cancel_num'])}</td>
		        </tr>
		        </volist>
		        <tr>
		        	<td align="right" colspan="4">商品总金额：</td>
		        	<td align="left">￥{$order.order_amt}</td>
		        </tr>
		        <tr>
		        	<td align="right" colspan="4">配送费：</td>
		        	<td align="left">￥{$order.order_send_fee}</td>
		        </tr>
		        <tr>
		        	<td align="right" colspan="4">订单支付金额：</td>
		        	<td align="left">￥{$order['order_amt']+$order['order_send_fee']}</td>
		        </tr>
			</tbody>
		</table>
	</div>
	<div><button type="button" onclick="printOrder()">打印订单</button></div>
<script type="text/javascript" src="__ROOT__/statics/scripts/jquery/jquery.PrintArea.js"></script>
<script type="text/javascript">

function doSubmit(){
	$('#form_edit').submit();
}
//商品打包
function readyPackage(){
	var formObj = document.forms['form_edit'];
	var elsObj = formObj.elements;
	elsObj['shop_saler'].value = $('#shop_saler').val();
	formObj.action = "{:U('Order/OrderManage/doReadyPackage')}";
	formObj.submit();
}
//商品配送
function readySend(){
	var formObj = document.forms['form_edit'];
	var elsObj = formObj.elements;
	elsObj['shop_sender'].value = $('#shop_sender').val();
	formObj.action = "{:U('Order/OrderManage/doReadySend')}";
	formObj.submit();
}
//订单支付
function readyPay(cust_order_status,cust_order_status_text){
	if(confirm("确定对该订单执行：【"+cust_order_status_text+"】？")){
		var formObj = document.forms['form_edit'];
		var elsObj = formObj.elements;
		elsObj['cust_order_status'].value = cust_order_status;
		formObj.action = "{:U('Order/OrderManage/doReadyPay')}";
		formObj.submit();
	}
}
//结单
function finishOrder(){
	if(confirm("确定对该订单执行：【结单】？")){
		var formObj = document.forms['form_edit'];
		var elsObj = formObj.elements;
		formObj.action = "{:U('Order/OrderManage/doFinishOrder')}";
		formObj.submit();
	}
}
//修改配送费用
function updOrderSendFee(){
	if(confirm("确定修改配送费用？")){
		var formObj = document.forms['form_edit'];
		var elsObj = formObj.elements;
		formObj.action = "{:U('Order/OrderManage/doUpdSendFee')}";
		formObj.submit();
	}
}
//单品退货
function cancelItem(order_code,id){
	//document.location.href = "/cart/doadd.html?prod_id="+prod_id+"&num="+num+"&edittype="+edittype;
	var cancelNum = parseInt( $("#prod_cancel_num"+id).val());
	var minNum =  parseInt( $("#prod_cancel_num"+id).attr('min'));
	var maxNum =  parseInt( $("#prod_cancel_num"+id).attr('max'));
	if(cancelNum>=minNum && cancelNum<=maxNum){
		if(!confirm('确定退货？')){
			return;
		}
	}else{
		alert('请输入正确的退货数量');
		return;
	}
	$.ajax({
		'async': true, 
        'url': "{:U('Order/OrderManage/doCancelItem')}",
        'dataType': "json",
        'data': {'order_code':order_code,'id':id,'prod_cancel_num':cancelNum},
        'success': function (data) {
        	if(data['error']=='0'){
	        	$("#prod_cancel_text"+id).html('已退货');
        	}else{
        		alert(data['message']);
        	}
        }
    });
} 
//订单备注
function updOrderBak(){
	var formObj = document.forms['form_edit'];
	var elsObj = formObj.elements;

	var order_code = elsObj['order_code'].value;
	var order_bak = elsObj['order_bak'].value;
	if(elsObj['order_bak'].value==''){
		alert('请输入订单备注');
		return ; 
	}
	$.ajax({
		'async': true, 
        'url': "{:U('Order/OrderManage/doUpdOrderBak')}",
        'dataType': "json",
        'data': {'order_code':order_code,'order_bak':order_bak},
        'success': function (data) {
        	alert(data['message']);
        }
    });
}

//订单打印
function printOrder(){
	//var options = { popup : "popup", popClose :true};
	var print = "div.PrintArea.orderPrint";
	$("div.PrintArea.orderPrint").printArea( );
}

</script>
</block>	